home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / util / libs / DigNet.lha / dignet / resourcetracking / demos / sources / DignetFreeTwice.asm next >
Encoding:
Assembly Source File  |  1997-03-12  |  4.3 KB  |  159 lines

  1. *>b:DignetFreeTwice
  2.  
  3.     *«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*
  4.     *   Copyright © 1997 by Kenneth C. Nilsen.  E-Mail: kennecni@IDGonline.no              *
  5.     *   Source viewed in 800x600 with Thin711.font (11) in CED                      *
  6.     *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  7.     *
  8.     *   Name
  9.     *    DignetFreeTwice 1.0
  10.     *
  11.     *   Synopsis
  12.     *       Demo program for dignet.library to show the resource tracking capability.
  13.     *
  14.     *   Inputs
  15.     *    DignetFreeTwice <device> [unit]   unit defaults to 0 if not provided
  16.     *
  17.     *   Notes
  18.     *
  19.     *   Bugs
  20.     *    
  21.     *   Created    : 12.03.97
  22.     *   Changes    : 12.03.97
  23.     *««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««*
  24.  
  25.  
  26. StartSkip    =    0
  27.  
  28. ;DODUMP        SET    1
  29.  
  30.  
  31.         Incdir    ""
  32.  
  33.         include    lvo:exec_lib.i
  34.         include    lvo:dos_lib.i
  35.         include    lvo:dignet_lib.i
  36.  
  37.         Incdir    inc:
  38.  
  39. ;these two files are included:
  40.  
  41.         include    dignet/dignet.i
  42.  
  43.         include    digital.macs
  44.         include    startup.asm
  45.  
  46.         Incdir    ""
  47.  
  48.         dc.b    "$VER: DignetFreeTwice 1.0 (12.3.97)",10
  49.         dc.b    "Copyright © 1997 Digital Surface. PUBLIC DOMAIN",0
  50.         even
  51. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  52. Init        TaskName    "DignetFreeTwice resource tracking demo"
  53.         DefLib    dignet,2        ;version 2 of dignet.library
  54.         DefLib    dos,37            ;version 37 of dos.library
  55.         DefEnd
  56.  
  57. Start    NextArg            ;any args for this program ?
  58.     beq    About        ;none, show About/usage
  59.     move.l    d0,a0
  60.     cmp.b    #'?',(a0)    ;info wanted ? show About/Usage
  61.     beq    About
  62.  
  63.     lea    DevN(pc),a1    ;we asume a device name
  64.  
  65. .copyDevice
  66.     move.b    (a0)+,(a1)+    ;copy name to our own buffer
  67.     bne.b    .copyDevice    ;you could easily default this to serial.device
  68.  
  69.     NextArg            ;unit provided ?
  70.     beq    .noUnit        ;if no unit provided, default to 0
  71.  
  72.     move.l    d0,a0        ;this is just a demo so we take a simple convert
  73.     move.b    (a0),d0
  74.     ext.w    d0
  75.     ext.l    d0
  76.     sub.w    #48,d0        ;simple convert
  77.     move.l    d0,Unit
  78.  
  79. .noUnit
  80.     LibBase    dignet
  81.  
  82.     lea    DevN(pc),a0    ;device we want to use
  83.     move.l    Unit(pc),d0    ;unit
  84.     Call    AllocNet    ;alloc a net structure
  85.     move.l    d0,Net        ;ok, it's ready for use
  86.     beq    ErrorNet
  87.  
  88.     move.l    Net(pc),a0    ;free once (as normal)
  89.     Call    FreeNet
  90.  
  91.     cmp.l    #dneterror_wrongnet,d0
  92.     beq    Freed
  93.  
  94.     move.l    Net(pc),a0    ;free second time (not normal.. normally a bug)
  95.     Call    FreeNet
  96.  
  97.     cmp.l    #dneterror_wrongnet,d0
  98.     beq    Freed
  99. *------------------------------------------------------------------------------------------------------------*
  100. Close    Return    0        ;quit program with 0 in return code
  101. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  102. Freed    lea    FreeError(pc),a0
  103.     bsr    Print
  104.     bra    Close
  105.  
  106. ErrorNet
  107.     LibBase    exec            ;report error on device/unit
  108.     lea    NoNetTxt(pc),a0
  109.     lea    Table(pc),a1
  110.     move.l    #DevN,(a1)
  111.     move.l    Unit(pc),4(a1)
  112.     lea    Proc(pc),a2
  113.     lea    Buffer(pc),a3
  114.     Call    RawDoFmt
  115.  
  116.     lea    Buffer(pc),a0
  117.     bsr    Print
  118.     bra    Close
  119.  
  120. About    lea    AboutTxt(pc),a0        ;About/Usage message
  121.     bsr    Print
  122.     bra    Close
  123.  
  124. Print    movem.l    d0-a6,-(sp)        ;our sub routine that prints to def. out
  125.  
  126.     LibBase    dos
  127.     move.l    a0,d2        ;backup string ptr.
  128.     Call    Output        ;get def. outhandler
  129.     move.l    d0,d1
  130.     beq    .exit        ;null ? then exit
  131.  
  132.     move.l    d2,a0        ;start count of length of string
  133.     moveq.l    #0,d3        ;length
  134. .count    tst.b    (a0)+        ;a null termination ?
  135.     beq.b    .print        ;yep, print
  136.     addq.l    #1,d3        ;no, add one more char
  137.     bra.b    .count        ;loop
  138. .print    Call    Write        ;write string to def Out which is our console
  139.  
  140. .exit    movem.l    (sp)+,d0-a6
  141.     rts
  142.  
  143. Proc    move.b    d0,(a3)+
  144.     rts
  145. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  146. Net        dc.l    0    ;ptr. to net structure
  147. Table        dc.l    0,0    ;ptr. table for RawDoFmt()
  148.  
  149. Unit        dc.l    0    ;unit number
  150. DevN        dcb.b    80,0    ;device name, insert "serial.device" in beginning to def. to that
  151.  
  152. Buffer        dcb.b    200,0    ;buffer for chars and RawDoFmt()
  153. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  154. NoNetTxt    dc.b    "Couldn't open %s unit %ld!",10,10,0
  155. AboutTxt    dc.b    "DignetFreeTwice 1.0 resource tracking demo program for dignet.library",10,10
  156.         dc.b    "USAGE: DignetFreeTwice <device> <unit>",10,10,0
  157. FreeError    dc.b    "The net sturucture was attempted to be freed after it was invalid!",10,0
  158. *»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»*
  159.